using System.Reflection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;

namespace GuavaLib
{
    public class GUIFilenameEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                if (!context.PropertyDescriptor.IsReadOnly)
                {
                    return UITypeEditorEditStyle.Modal;
                }
            }
            return UITypeEditorEditStyle.None;
        }

        [RefreshProperties(RefreshProperties.All)]
        public override object EditValue(ITypeDescriptorContext context,
                                    System.IServiceProvider provider,
                                    object value)
        {
            if (context == null || provider == null || context.Instance == null)
            {
                return base.EditValue(provider, value);
            }
            GLaunchForm frmLaunch = new GLaunchForm(value as string);
            if (frmLaunch.ShowDialog() == DialogResult.OK)
            {
                value = frmLaunch.GetSelectedClassName();
                return value;
            }
            return value;
        }
    }
}
